const express = require('express')
const router = express.Router()
const reviewService = require('services/review')

router.get('/', async (req, res, next) => {
  try {
    res.json(await reviewService.getAll(req.query, req.query.page))
  } catch (e) {
    next(e)
  }
})

router.post('/:id/pass', async (req, res, next) => {
  try {
    await reviewService.auditPass(req.params.id)
    res.json({status: "ok"})
  } catch (e) {
    next(e)
  }
})

router.post('/:id/toggleSelected', async (req, res, next) => {
  try {
    await reviewService.toggleSelected(req.params.id, req.body.isSelected)
    res.json({status: "ok"})
  } catch (e) {
    next(e)
  }
})

router.post('/:id/reject', async (req, res, next) => {
  try {
    await reviewService.auditReject(req.params.id)
    res.json({status: "ok"})
  } catch (e) {
    next(e)
  }
})

module.exports = router